home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2000 January / Macworld (2000-01).dmg / Shareware World / Utilities / Text processing / PDF–Blit™1.02.sea / PDF–Blit™1.02 / Source / pdfOutputDialog.c < prev    next >
Text File  |  1999-09-17  |  9KB  |  346 lines

  1. // ©1999 by Kas Thomas. All rights reserved. See ReadMe for important information.
  2. #include <Controls.h>
  3. #include <BBXTInterface.h>
  4. #include "p_intern.h"
  5. #include <ExternalInterface.h>
  6. #include <DialogUtilities.h>
  7. #include "pdfPrefs.h"
  8. #include <TextUtils.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <Strings.h>
  13. #include <ctype.h>
  14. #include <Appearance.h>
  15. void CopyPtoC( Str63 p, char *c);
  16. void CopyCtoP( char *c, Str63 p);
  17. pascal Boolean ourPrefsDialogFilter (DialogPtr dp,
  18. EventRecord *event,
  19. short *item);
  20. void PStrCopy(Str255 p1,Str255 p2);
  21. int IsNumeric(char *str);
  22. typedef struct popupPrivateData {
  23. MenuHandle mHandle; 
  24. short mID;        
  25. }popupPrivateData;
  26.  
  27. Str63 fontnames[] =  { "\p","\pHelvetica","\pHelvetica-Bold","\pHelvetica-Oblique","\pHelvetica-BoldOblique",
  28. "\pTimes-Roman","\pTimes-Bold","\pTimes-Italic","\pTimes-BoldItalic","\pCourier","\pCourier-Bold","\pCourier-Oblique","\pCourier-BoldOblique"};
  29. Str63 transitionNames[] =  { "\p","\pwipe","\pdissolve","\pbox","\psplit","\pblinds","\preplace","\pglitter"};
  30.  
  31. OSErr DoDialog(ExternalCallbackBlock *callbacks, PrefsPtr pp)
  32. {
  33. unsigned charsearch_str[128];
  34. short iType, checkBoxVal;
  35. Rect iRect;
  36. Handle prefResource,iHandle = nil;
  37. short item,i;
  38. long offset;
  39. OSErr err = noErr;
  40. DialogPtr d;
  41. GrafPtr save_port;
  42. unsigned char tmp[32];
  43. Str63 pstr;
  44. Prefs backup;
  45. ControlHandle ch1,ch2;
  46. DialogTHndl dt;
  47. BlockMove(pp,&backup,sizeof(Prefs));
  48. GetPort(&save_port);
  49.  
  50. dt = (DialogTHndl) GetResource ('DLOG', 1020);
  51. HNoPurge ((Handle) dt);
  52. d = GetNewDialog ( 1020, nil, (WindowPtr)-1 );
  53. SetPort( (GrafPtr)d ) ;
  54. err =  SetDialogDefaultItem(d, ok) ;
  55. SetWRefCon( d, (long)pp );
  56. {
  57. long  *ptl;
  58. SetRect( &iRect, 8,20,8 + 120,20 + 20); 
  59. ch1 = NewControl( d, &iRect, "\p", true, 128, 0,
  60. 0, kControlBevelButtonSmallBevelProc , 0L );
  61. SetControlValue(ch1,0);
  62. offset = (long)*(**ch1).contrlData;
  63. offset += 12L;
  64. ptl = (long *)offset;
  65. *ptl = (long) pp->font ;
  66. PStrCopy((*ch1)->contrlTitle,fontnames[ pp->font ]);
  67. SetRect( &iRect, 224,20,224 + 138,20 + 20); 
  68. ch2 = NewControl( d, &iRect, "\p", true, 129, 0,
  69. 0, kControlBevelButtonSmallBevelProc , 0L );
  70. offset = (long)*(**ch2).contrlData;
  71. offset += 12L; 
  72. ptl = (long *)offset;
  73. *ptl = (long) pp->transition ;
  74. PStrCopy((*ch2)->contrlTitle,transitionNames[ pp->transition ]);
  75. }
  76. CopyCtoP((char *)pp->author,pstr);
  77. SetStrItem(d, AUTHOR_ITEM,pstr);
  78. CopyCtoP((char *)pp->title,pstr);
  79. SetStrItem(d, TITLE_ITEM,pstr);
  80. CopyCtoP((char *)pp->keywords,pstr);
  81. SetStrItem(d, KEYWORDS_ITEM,pstr);
  82. sprintf((char *)tmp,"%3.1f",pp->ptsize);
  83. CopyCtoP((char *)tmp,pstr);
  84. SetStrItem(d,POINTSIZE_ITEM,pstr);
  85. sprintf((char *)tmp,"%3.1f",pp->leading);
  86. CopyCtoP((char *)tmp,pstr);
  87. SetStrItem(d,LEADING_ITEM,pstr);
  88. sprintf((char *)tmp,"%i",pp->spaces);
  89. CopyCtoP((char *)tmp,pstr);
  90. SetStrItem(d,SPACESPERTAB_ITEM,pstr);
  91. sprintf((char *)tmp,"%i",pp->marginTop);
  92. CopyCtoP((char *)tmp,pstr);
  93. SetStrItem(d,MARGINTOP,pstr);
  94. sprintf((char *)tmp,"%i",pp->marginBot);
  95. CopyCtoP((char *)tmp,pstr);
  96. SetStrItem(d,MARGINBOT,pstr);
  97. sprintf((char *)tmp,"%i",pp->marginLeft);
  98. CopyCtoP((char *)tmp,pstr);
  99. SetStrItem(d,MARGINL,pstr);
  100. sprintf((char *)tmp,"%i",pp->marginRt);
  101. CopyCtoP((char *)tmp,pstr);
  102. SetStrItem(d,MARGINR,pstr);
  103. sprintf((char *)tmp,"%i",pp->chwidth);
  104. CopyCtoP((char *)tmp,pstr);
  105. SetStrItem(d,CHWIDTH_ITEM,pstr);
  106. GetDialogItem(d, PAGENO_ITEM, &iType, &iHandle, &iRect);
  107. SetControlValue((ControlHandle) iHandle, pp->numberPages);
  108. GetDialogItem(d, JUSTIFY_ITEM, &iType, &iHandle, &iRect);
  109. SetControlValue((ControlHandle) iHandle, pp->justify);
  110. XAbleDlgCtl(d,HTML_ITEM,!pp->justify);
  111. GetDialogItem(d, ACROBAT_ITEM, &iType, &iHandle, &iRect);
  112. SetControlValue((ControlHandle) iHandle, pp->launchAcrobat);
  113. GetDialogItem(d, HEADER_ITEM, &iType, &iHandle, &iRect);
  114. SetControlValue((ControlHandle) iHandle, pp->header);
  115. GetDialogItem(d, HTML_ITEM, &iType, &iHandle, &iRect);
  116. SetControlValue((ControlHandle) iHandle, pp->interpHTML);
  117. XAbleDlgCtl(d,JUSTIFY_ITEM,!pp->interpHTML);
  118. InitCursor();
  119. do {
  120. ModalDialog(ourPrefsDialogFilter, &item);
  121. if (item == JUSTIFY_ITEM) 
  122. {
  123. pp->justify = !pp->justify;
  124. SetDlgCtl(d, item, pp->justify);
  125. XAbleDlgCtl(d,HTML_ITEM,!pp->justify);
  126. }
  127. if (item == HEADER_ITEM) 
  128. {
  129. pp->header = !pp->header;
  130. SetDlgCtl(d, item, pp->header);
  131. }
  132. if (item == HTML_ITEM) 
  133. {
  134. pp->interpHTML = !pp->interpHTML;
  135. SetDlgCtl(d, item, pp->interpHTML);
  136. XAbleDlgCtl(d,JUSTIFY_ITEM,!pp->interpHTML);
  137. }
  138. if (item == AUTHOR_ITEM) { 
  139. Str63 s;
  140. ReadStrItem(d, AUTHOR_ITEM, s);
  141. CopyPtoC(s,(char *)pp->author );
  142. }
  143. if (item == TITLE_ITEM) { 
  144. Str63 s;
  145. ReadStrItem(d, TITLE_ITEM, s);
  146. CopyPtoC( s,(char *)pp->title );
  147. }
  148. if (item == KEYWORDS_ITEM) { 
  149. Str63 s;
  150. ReadStrItem(d, KEYWORDS_ITEM, s);
  151. CopyPtoC( s,(char *)pp->keywords );
  152. }
  153. if (item == SPACESPERTAB_ITEM) {
  154. Str63 s; char temp2[12];
  155. ReadStrItem(d, SPACESPERTAB_ITEM, s);
  156. CopyPtoC(s,temp2);
  157. if (!IsNumeric(temp2))
  158. { SysBeep(1); continue; }
  159. pp->spaces = atoi(temp2);
  160. }
  161. if (item == PAGENO_ITEM) { 
  162. pp->numberPages = !pp->numberPages;
  163. SetDlgCtl(d, item, pp->numberPages);
  164. }
  165. if (item == ACROBAT_ITEM) { 
  166. pp->launchAcrobat = !pp->launchAcrobat;
  167. SetDlgCtl(d, item, pp->launchAcrobat);
  168. }
  169. if (item == MARGINTOP) {
  170. Str63 s; char temp3[12];
  171. ReadStrItem(d, MARGINTOP, s);
  172. CopyPtoC(s,temp3);
  173. if (!IsNumeric(temp3))
  174. { SysBeep(1); continue; }
  175. pp->marginTop = atoi(temp3);
  176. pp->marginTop += pp->leading;
  177. }
  178. if (item == MARGINBOT) {
  179. Str63 s; char temp3[12];
  180. ReadStrItem(d, MARGINBOT, s);
  181. CopyPtoC(s,temp3);
  182. if (!IsNumeric(temp3))
  183. { SysBeep(1); continue; }
  184. pp->marginBot = atoi(temp3);
  185. }
  186. if (item == MARGINL) {
  187. Str63 s; char temp3[12];
  188. ReadStrItem(d, MARGINL, s);
  189. CopyPtoC(s,temp3);
  190. if (!IsNumeric(temp3))
  191. { SysBeep(1); continue; }
  192. pp->marginLeft = atoi(temp3);
  193. }
  194. if (item == MARGINR) {
  195. Str63 s; char temp3[12];
  196. ReadStrItem(d, MARGINR, s);
  197. CopyPtoC(s,temp3);
  198. if (!IsNumeric(temp3))
  199. { SysBeep(1); continue; }
  200. pp->marginRt = atoi(temp3);
  201. }
  202. if (item == CHWIDTH_ITEM) {
  203. Str63 s; char temp6[12];
  204. ReadStrItem(d, CHWIDTH_ITEM, s);
  205. CopyPtoC(s,temp6);
  206. if (!IsNumeric(temp6))
  207. { SysBeep(1); continue; }
  208. pp->chwidth = atoi(temp6);
  209. }
  210. if (item == POINTSIZE_ITEM) { 
  211. Str63 s; char temp4[12]; double fl; int pt = '.';
  212. ReadStrItem(d, POINTSIZE_ITEM, s);
  213. CopyPtoC(s,temp4); 
  214. if (!IsNumeric(temp4))
  215. { SysBeep(1); continue; }
  216. fl = atoi(temp4);
  217. if(strchr(temp4,pt) != NULL) {
  218. if (s[*s] == '.') ;
  219. else {
  220. s[1] = s[*s]; *s = 1;
  221. CopyPtoC(s,temp4); 
  222. fl += (float)atoi(temp4)/10.;
  223. }
  224. }
  225. pp->ptsize = fl;
  226. }
  227. if (item == LEADING_ITEM) { 
  228. Str63 s; char temp5[12]; double fk; int pt = '.';
  229. ReadStrItem(d, LEADING_ITEM, s);
  230. CopyPtoC(s,temp5); 
  231. if (!IsNumeric(temp5))
  232. { SysBeep(1); continue; }
  233. fk = atoi(temp5);
  234. if(strchr(temp5,pt) != NULL) {
  235. if (s[*s] == '.') ;
  236. else {
  237. s[1] = s[*s]; *s = 1;
  238. CopyPtoC(s,temp5); 
  239. fk += (float)atoi(temp5)/10.;
  240. }
  241. }
  242. pp->leading = fk;
  243. }
  244.  
  245. } while ((item != 1) && (item != 2));
  246. if (item == 2) { 
  247. err = -1; 
  248. BlockMove( &backup,pp,sizeof(Prefs));
  249. }
  250.  
  251. DisposeDialog(d);
  252. SetPort(save_port);
  253. HPurge ((Handle) dt);
  254. return err;
  255. }
  256.  
  257.  
  258. pascal Boolean ourPrefsDialogFilter (DialogPtr dp,
  259. EventRecord *event,
  260. short *item)
  261. {
  262. Rect pop1, pop2, r;
  263. Boolean result = false;
  264. ControlHandle theControl;
  265. WindowPtr fw = FrontWindow();
  266. Point local;
  267. PrefsPtr pp = (PrefsPtr) GetWRefCon(dp);
  268. char charCode;
  269.  
  270. SetRect( &pop1, 8,20,8 + 120,20 + 20); 
  271. SetRect( &pop2, 224,20,224 + 138,20 + 20); 
  272.  
  273. local.v = (event->where).v;
  274. local.h = (event->where).h;
  275.  
  276. r = (**((WindowPeek) fw)->contRgn).rgnBBox;
  277. local.h -= r.left;
  278. local.v -= r.top;
  279. switch (event->what) {
  280. case mouseDown:
  281. if (PtInRect(local, &pop1) ) { 
  282. if (FindControl(local, dp, &theControl))
  283. if (TrackControl(theControl, local,(ControlActionUPP) -1)) {
  284. long l,*ptl;
  285. l = (long)*(**theControl).contrlData;
  286. l += 12L;
  287. ptl = (long *) l;
  288. pp->font = *ptl ;
  289. PStrCopy((*theControl)->contrlTitle,fontnames[ pp->font ]);
  290. InvalRect(&pop1);
  291. }
  292. break;
  293. if (PtInRect(local, &pop2) ) { 
  294. if (FindControl(local, dp, &theControl))
  295. if (TrackControl(theControl, local,(ControlActionUPP) -1)) {
  296. long l,*ptl;
  297. l = (long)*(**theControl).contrlData;
  298. l += 12L;
  299. ptl = (long *) l;
  300. pp->transition = *ptl ;
  301. PStrCopy((*theControl)->contrlTitle,transitionNames[ pp->transition ]);
  302. InvalRect(&pop2);
  303. }
  304. break;
  305. case autoKey:
  306. case keyDown:
  307. charCode = event->message & charCodeMask;
  308. if (charCode == 3 || charCode == 0x0D) {
  309. *item = 1;
  310. result = true;
  311. break;
  312. }
  313. break;
  314. default: break;
  315. return result;
  316.  
  317. void CopyCtoP( char *c, Str63 p) {
  318. int i=0;
  319. char *t = c;
  320. while (*t) { t++; i++; }
  321. BlockMove(c,p+1,i);
  322. *p=i;
  323. }
  324. void CopyPtoC( Str63 p, char *c) {
  325. int i = *p;
  326. BlockMove(p+1,c,i);
  327. c[i] = 0x00;
  328. }
  329. void PStrCopy(Str255 p1,Str255 p2) {
  330. int i = *p2;
  331. BlockMove(p2+1,p1+1,i);
  332. *p1 = *p2;
  333. }
  334. int IsNumeric(char *str) {
  335. char *p = str;
  336. while (*p)
  337. if (!isdigit(*p) && *p != '.')
  338. return 0;
  339. else p++;
  340. return 1;
  341. }
  342.